package com.xiongjie;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.template.PebbleTemplate;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

public class PebbleUtil {

    //Pebble模版引擎也有继承和重写关系--和java类似
    public static void main(String[] args) throws IOException {
//        hello();

        autoescape();
    }

    public static void hello() throws IOException {
        PebbleEngine engine = new PebbleEngine.Builder().build();
        PebbleTemplate compiledTemplate = engine.getTemplate("home.peb");

        Map<String, Object> context = new HashMap<>();
        context.put("name", "Mitchell");

        Writer writer = new StringWriter();
        compiledTemplate.evaluate(writer, context);

        String output = writer.toString();
        System.out.println(output);
    }

//*********************Tags**************************

    public static void autoescape() throws IOException {
        PebbleEngine engine = new PebbleEngine.Builder().build();
        PebbleTemplate compiledTemplate = engine.getTemplate("tags.peb");

        Map<String, Object> map = new HashMap<>();
        Writer writer = new StringWriter();
        compiledTemplate.evaluate(writer, map);

        String output = writer.toString();
        System.out.println(output);
    }
}
